{*******************************************************************************
* The contents of this file are used with permission, subject to the Mozilla   *
* Public License Version 1.1 (the "License"); you may not use this file except *
* in compliance with the License. You may obtain a copy of the License at      *
* http://www.mozilla.org/MPL/                                                  *
*                                                                              *
* Software distributed under the License is distributed on an "AS IS" basis,   *
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for *
* the specific language governing rights and limitations under the License.    *
*                                                                              *
* The Original Code is distributed as part of the "mediate" product and is     *
* Copyright (C) @home media limited. All Rights Reserved.                      *
*                                                                              *
* Email: support@athomemedia.co.uk                                             *
* Web:   http://www.athomemedia.co.uk                                          *
*******************************************************************************}

unit PluginPropsForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, PluginManager;

type
  TfrmPluginProperties = class(TForm)
    btClose: TButton;
    mmDocumentation: TMemo;
    Label1: TLabel;
    Label3: TLabel;
    Label5: TLabel;
    Label7: TLabel;
    Label9: TLabel;
    Label11: TLabel;
    btConfigure: TButton;
    edName: TEdit;
    edDescription: TEdit;
    edFilename: TEdit;
    edVersion: TEdit;
    edAuthor: TEdit;
    edInternalName: TEdit;
    Label2: TLabel;
    procedure FormShow(Sender: TObject);
    procedure btConfigureClick(Sender: TObject);
  private
    { Private declarations }
    FPlugin: TAHMPluginWrapper;
    FPluginName: String;
    procedure SetInternalName(PluginName: String);
  public
    { Public declarations }
    property InternalName: String read FPluginName write SetInternalName;
    class function ShowProperties(PluginName: String): TModalResult;
    class procedure ShowConfiguration(PluginName: String);
  end;


implementation

{$R *.dfm}

uses ApplicationManager;

class function TfrmPluginProperties.ShowProperties(PluginName: String): TModalResult;
begin
  with TfrmPluginProperties.Create(Application.MainForm) do
  try
    PopupParent := Application.MainForm;
    InternalName := PluginName;
    Result := ShowModal;
  finally
    Free;
  end;
end;

class procedure TfrmPluginProperties.ShowConfiguration(PluginName: String);
begin
  with TfrmPluginProperties.Create(Application.MainForm) do
  try
    PopupParent := Application.MainForm;
    InternalName := PluginName;
    btConfigure.Click;
  finally
    Free;
  end;
end;

procedure TfrmPluginProperties.SetInternalName(PluginName: String);
begin
  // Load plugin for inspection/configuration
  FPlugin := ApplicationManagerInstance.PluginManager.InspectPlugin(PluginName);
  FPluginName := PluginName;
end;

procedure TfrmPluginProperties.FormShow(Sender: TObject);
begin
  if Assigned(FPlugin) then
  begin
    edName.Text := FPlugin.Name;
    edDescription.Text := FPlugin.Description;
    edInternalName.Text := FPlugin.InternalName;
    edFilename.Text := FPlugin.Path;
    edVersion.Text := FPlugin.Version;
    edAuthor.Text := FPlugin.Author;
    mmDocumentation.Lines.Text := FPlugin.Comment;
    btConfigure.Enabled := FPlugin.Configurable;
  end
  else
  begin
    edName.Text := '';
    edDescription.Text := '';
    edInternalName.Text := '';
    edFilename.Text := '';
    edVersion.Text := '';
    edAuthor.Text := '';
    mmDocumentation.Lines.Clear;
    btConfigure.Enabled := False;
  end;
end;

procedure TfrmPluginProperties.btConfigureClick(Sender: TObject);
begin
  if Assigned(FPlugin) and (not FPlugin.Configure) then
    MessageDlg('This plugin does not have any configurable properties.', mtInformation, [mbOK], 0);
end;


end.
